package com.rickpan.entity;

import jakarta.persistence.*;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * VIP功能使用记录实体类
 */
@Entity
@Table(name = "vip_usage_records", 
    indexes = {
        @Index(name = "idx_user_feature_date", columnList = "userId, featureCode, usageDate"),
        @Index(name = "idx_usage_date", columnList = "usageDate"),
        @Index(name = "idx_feature_code", columnList = "featureCode"),
        @Index(name = "idx_user_id", columnList = "userId")
    },
    uniqueConstraints = {
        @UniqueConstraint(name = "uk_user_feature_date", columnNames = {"userId", "featureCode", "usageDate"})
    }
)
@Data
public class VipUsageRecord {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 用户ID
     */
    @Column(nullable = false)
    private Long userId;

    /**
     * 功能代码
     */
    @Column(nullable = false, length = 50)
    private String featureCode;

    /**
     * 使用日期
     */
    @Column(nullable = false)
    private LocalDate usageDate;

    /**
     * 使用次数
     */
    @Column(nullable = false)
    private Integer usageCount = 1;

    /**
     * 使用详情(JSON格式)
     */
    @Column(columnDefinition = "JSON")
    private String usageDetails;

    /**
     * 创建时间
     */
    @Column(nullable = false, updatable = false)
    private LocalDateTime createdAt;

    @PrePersist
    protected void onCreate() {
        createdAt = LocalDateTime.now();
    }
}